package br.com.ilhasoft.support.validation.validator;

import br.com.ilhasoft.support.validation.rule.Rule;
import br.com.ilhasoft.support.validation.rule.CpfTypeRule;
import br.com.ilhasoft.support.validation.rule.UsernameRule;
import br.com.ilhasoft.support.validation.rule.EmailTypeRule;
import br.com.ilhasoft.support.validation.rule.UrlTypeRule;
import br.com.ilhasoft.support.validation.rule.CreditCardTypeRule;
import ohos.agp.components.Text;


public class TypeValidator {
    /**
     * 验证规则绑定
     * @param view
     * @param fieldTypeText
     * @param content
     * @param errorMessage
     * @param autoDismiss
     */
    public static void bindingTypeValidation(Text view, String fieldTypeText,String content,
        String errorMessage, boolean autoDismiss) {
        Rule rule = null;
        switch(fieldTypeText){
            case "cpf":
               rule =  new CpfTypeRule(view , content , errorMessage);
                break;
            case "username":
                rule =  new UsernameRule(view , content , errorMessage);
                break;
            case "email":
                rule =  new EmailTypeRule(view , content , errorMessage);
                break;
            case "url":
                rule =  new UrlTypeRule(view , content , errorMessage);
                break;
            case "creditcard":
                rule =  new CreditCardTypeRule(view , content , errorMessage);
                break;
        }
        if (rule != null){
            rule.validate();
        }
    }
}
